/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cuentaletras;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hidrocaribe
 */
public class CuentaLetras {

    public static void main(String[] args) {
        String line = "";
        final String ruta = "/home/alexis/Readme.txt";
        try {
            FileReader fr = new FileReader(ruta);
            BufferedReader br = new BufferedReader(fr);
            if (args.length > 1) {
                System.out.print("muchos argumentos");
            } else if (args.length == 0) {
                System.out.println("Indique caracter a buscar");
            } else if (args[0].length() != 1) {
                System.out.println("Indique solo un caracter");
            } else {
                int total = 0;
                char caracter = args[0].charAt(0);
                while (line != null) {
                    line = br.readLine();  //lee la linea
                    System.out.println("**** "+line);
                    if (line != null) {
                        
                        for (int i = 0; i < line.length(); i++) {
                            //System.out.println(line.charAt(i));
                            if (caracter == line.charAt(i)) {
                                total++;
                            }
                        }
                    }
                }
                System.out.println(caracter + " Se encontro " + total + " veces");
            }

        } catch (FileNotFoundException ex) {
            Logger.getLogger(CuentaLetras.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CuentaLetras.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
